package com.example.demo.controller;

import com.example.demo.core.Result;
import com.example.demo.entity.Town;
import com.example.demo.service.TownService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 地理位置镇/街道控制器
 *
 * @author 叮当猫的百宝箱
 * @since 1.0
 */
@Tag(name = "地理位置镇/街道信息", description = "地理位置镇/街道信息")
@RestController
@RequestMapping("/geo")
@RequiredArgsConstructor
public class TownController {

    private final TownService townService;

    /**
     * 根据区/县编码获取辖区的镇/街道级行政辖区列表
     *
     * @param districtCode 区/县行政编码
     * @return API全局响应对象
     */
    @GetMapping("/district/{districtCode}/town")
    public Result<List<Town>> getTownListByDistrictCode(@PathVariable("districtCode") String districtCode) {
        List<Town> townList = townService.getByDistrictCode(districtCode);
        return Result.ok(townList);
    }
}
